package AuthorityAgent;

import jade.content.lang.Codec;
import jade.content.lang.sl.SLCodec;
import jade.content.onto.Ontology;
import jade.core.Agent;
import jade.domain.FIPANames;
import jade.lang.acl.MessageTemplate;
import wwtp.ontology.Biological;
import wwtp.ontology.Chemical;
import wwtp.ontology.Physical;
import wwtp.ontology.Volume;
import wwtp.ontology.WWTPAmazingOntology;
import wwtp.ontology.Water;
import DataBases.DBDirectWater;
import DataBases.DBToxicNotification;
import DataBases.DBWaterAnalysis;

public class AuthorityAgent extends Agent{

	protected Codec codec = new SLCodec();
	protected Ontology ontology = WWTPAmazingOntology.getInstance();
	DBDirectWater dbDirectWater;
	DBWaterAnalysis dbWaterAnalysis;
	DBToxicNotification dbToxicNotification;
	Water water;
	public boolean negotiating;

	protected void setup(){

		getContentManager().registerLanguage(codec);
		getContentManager().registerOntology(ontology);
		dbDirectWater = DBDirectWater.getInstance();
		dbWaterAnalysis = DBWaterAnalysis.getInstance();
		dbToxicNotification = DBToxicNotification.getInstance();

		negotiating = false;

		water = new Water();
		Biological b = new Biological();
		b.setPercentaje(15);
		water.setBiological(b);
		Chemical c = new Chemical();
		c.setPercentaje(10);
		water.setChemical(c);
		Physical p = new Physical();
		p.setPercentaje(5);
		water.setPhysical(p);
		Volume v = new Volume();
		v.setLitres(100);
		water.setVolume(v);

		addBehaviour(new AuthorityInflowWaterBehaviour());
		addBehaviour(new NotificationsReceiverBehaviour());
		MessageTemplate mt = MessageTemplate.and(
				MessageTemplate.MatchConversationId("HelpRequest"),
				MessageTemplate.MatchProtocol(FIPANames.InteractionProtocol.FIPA_QUERY)
				);
		addBehaviour(new HelpRequestHandlerBehaviour(this, mt));

		System.out.println("Agent created with name: "+getAID().getName());
	}

	@Override
	protected void takeDown() {
		System.out.println("======================> ERASING: "+getAID().getName());
	}
}
